package com.hatricks.is.exchangerate;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;

/**
 * @packageName: com.hatricks.makemoney
 * @className: ExchangeRateUtils
 * @author: yanyuhui y568821795@outlook.com
 * @date: 2023/5/23 22:22
 * @description: 实时获取汇率
 */
public class ExchangeRateUtils {

    public static void main(String[] args) {
        // 发起GET请求获取汇率数据
        // 这里以获取美元兑其他货币汇率为例
        HttpRequest request = HttpUtil.createGet("https://api.exchangerate-api.com/v4/latest/CNY");
        try (HttpResponse response = request.execute()) {
            String body = response.body();
            System.out.println(body);
        }
        // 读取响应数据
        // 获取指定货币的汇率
        //double gbpRate = rates.getDouble("GBP"); // 获取英镑对美元的汇率
        //System.out.println("GBP to USD exchange rate: " + gbpRate);
    }
}






